//  MagzineViewController.m
//  TextApplication
//
//  Created by dllo on 16/8/27.
//  Copyright © 2016年 yh. All rights reserved.


#import "MagzineViewController.h"
#import "TAMacro.h"
#import "MagzineTableViewCell.h"
#import "ZWYNetTool.h"
#import "UIImageView+WebCache.h"
#import "MagzineFootView.h"
#import "MagzineCollectionViewCell.h"
#import "MagzineBrandCollectModel.h"
#import "WriterTableViewCell.h"
#import "MagzineWriterModel.h"
#import "MagzineDetailViewController.h"

#import "MJRefresh.h"
#import "MBProgressHUD.h"

@interface MagzineViewController () <UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *magzineArray;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UIView *footView;
@property (nonatomic, strong) UILabel *footLabel;
@property (nonatomic, copy) NSString *dataStr;
@property (nonatomic, strong) UIButton *topViewButton;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *dataButton;

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIButton *brandButton;
@property (nonatomic, strong) UIButton *magzineButton;
@property (nonatomic, strong) UIView *aView;

@property (nonatomic, strong) NSMutableArray *collectArray;
@property (nonatomic, strong) UIView *collectTopView;
@property (nonatomic, strong) UIScrollView *backScrollView;
@property (nonatomic, strong) UITableView *writertableView;

@property (nonatomic, strong) NSMutableArray *writerArray;

@property (nonatomic, strong) UIButton *topBrandButton;
@property (nonatomic, strong) UIButton *writerButton;

@property (nonatomic, assign) NSInteger sectionIndex;
@property (nonatomic, assign) NSInteger rowIndex;

@property (nonatomic, copy) NSString *idStr;
@property (nonatomic, copy) NSString *str7;

@property (nonatomic, copy) NSString *writerId;

@end

@implementation MagzineViewController

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidDisappear:(BOOL)animated {
    self.navigationController.navigationBar.hidden = NO;
}




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 还有分区
    self.view.backgroundColor = [UIColor blackColor];
    //    self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0.180 alpha:1.000];
    [self createScrollView];
    [self createWriterTableView];
    [self createCollectionView];
    [self createTopButton];
    self.dataButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self createTableView];
    [self createWriterData];
    [self createData];
    [self createCollectionViewData];
    
}

- (void)createScrollView {
    self.backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 44)];
    self.backScrollView.contentSize = CGSizeMake(WIDTH * 2, 0);
    self.backScrollView.delegate = self;
    [self.view addSubview:self.backScrollView];
    self.backScrollView.pagingEnabled = YES;
    if (self.backScrollView.contentOffset.x == 0) {
        [self.topBrandButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.writerButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    } else if(self.backScrollView.contentOffset.x == WIDTH) {
        [self.topBrandButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.writerButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (self.backScrollView.contentOffset.x == 0) {
        [self.topBrandButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.writerButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    } else if(self.backScrollView.contentOffset.x == WIDTH) {
        [self.topBrandButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.writerButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
}

- (void)createCollectionViewData {
    self.collectArray = [NSMutableArray array];
    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    [ZWYNetTool GET:@"http://mobile.iliangcang.com/topic/magazineCatList/?&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981" andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSArray *array = result[@"data"][@"items"];
        for (NSDictionary *dic in array) {
            MagzineBrandCollectModel *magzine = [MagzineBrandCollectModel modelWithDic:dic];
            [self.collectArray addObject:magzine];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.collectionView reloadData];
            });
        }
    } andFailureBlock:^(NSError *error) {
    }];
    
    
    
    //    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    //    [ZWYNetTool GET:@"http://mobile.iliangcang.com/topic/magazineCatList/?&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981" andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
    //        NSArray *array = result[@"data"][@"items"];
    //        for (NSDictionary *dic in array) {
    //            self.collectArray = [NSMutableArray array];
    //            MagzineBrandCollectModel *magzine = [MagzineBrandCollectModel modelWithDic:dic];
    //            [self.collectArray addObject:magzine];
    //            dispatch_async(dispatch_get_main_queue(), ^{
    //                [self.collectionView reloadData];
    //            });
    //        }
    //    } andFailureBlock:^(NSError *error) {
    //    }];
}

// 创建最上面的button
- (void)createTopButton {
    self.topViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.topViewButton.frame = CGRectMake(0, 0, WIDTH, 64);
    self.topViewButton.backgroundColor = [UIColor colorWithWhite:0.180 alpha:1.000];
    [self.view addSubview:self.topViewButton];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.topViewButton.bounds.size.width / 2 - 25, 25, 50, 30)];
    self.titleLabel.text = @"杂志";
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.textAlignment = 1;
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.topViewButton addSubview:self.titleLabel];
    
    self.brandButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.brandButton.frame = CGRectMake(WIDTH / 2 + 20, 30, 20, 20);
    [self.brandButton setImage:[UIImage imageNamed:@"23"] forState:UIControlStateNormal];
    [self.topViewButton addSubview:self.brandButton];
    [self.brandButton addTarget:self action:@selector(brandClick:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)brandClick:(UIButton *)button {
    [UIView animateWithDuration:1 animations:^{
        self.topViewButton.frame = CGRectMake(0, 0, WIDTH, self.tabBarController.tabBar.bounds.size.height);
        [self.tabBarController.tabBar addSubview:self.topViewButton];
        self.tableView.frame = CGRectMake(0, HEIGHT + 44, WIDTH, HEIGHT);
    }];
    self.titleLabel.frame = CGRectMake(self.topViewButton.bounds.size.width / 2 - 25, 7, 50, 30);
    self.dataButton.hidden = YES;
    self.brandButton.hidden = YES;
    self.magzineButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.magzineButton setImage:[UIImage imageNamed:@"24"] forState:UIControlStateNormal];
    self.magzineButton.frame = CGRectMake(WIDTH / 2 + 25, 15, 10, 15);
    [self.topViewButton addSubview:self.magzineButton];
    [self.magzineButton addTarget:self action:@selector(magzineClick:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)magzineClick:(UIButton *)button {
    self.dataButton.hidden = NO;
    self.magzineButton.hidden = YES;
    self.brandButton.hidden = NO;
    [UIView animateWithDuration:1 animations:^{
        self.topViewButton.frame = CGRectMake(0, 0, WIDTH, 64);
        [self.view addSubview:self.topViewButton];
        self.tableView.frame = CGRectMake(0, 64, WIDTH, HEIGHT - 64);
    }];
    self.titleLabel.frame = CGRectMake(self.topViewButton.bounds.size.width / 2 - 25, 25, 50, 30);
}

- (void)createCollectionView {
    self.collectTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 64)];
    self.collectTopView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectTopView];
    self.topBrandButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.topBrandButton.frame = CGRectMake(WIDTH / 4 - 30, 30, 60, 30);
    [ self.topBrandButton setTitle:@"分类" forState:UIControlStateNormal];
    if (self.backScrollView.contentOffset.x == 0) {
        [ self.topBrandButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    } else {
        [ self.topBrandButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    }
    [ self.topBrandButton addTarget:self action:@selector(brandButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.collectTopView addSubview: self.topBrandButton];
    self.writerButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.writerButton.frame = CGRectMake(WIDTH / 4 * 3 - 30, 30, 60, 30);
    [self.writerButton setTitle:@"作者" forState:UIControlStateNormal];
    [self.writerButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.writerButton addTarget:self action:@selector(writerButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.collectTopView addSubview:self.writerButton];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((WIDTH - 45) / 2, WIDTH / 3);
    layout.minimumInteritemSpacing = 15;
    layout.minimumLineSpacing = 15;
    layout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 108) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.backScrollView addSubview:self.collectionView];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    [self.collectionView registerClass:[MagzineCollectionViewCell class] forCellWithReuseIdentifier:@"collectReuse"];
}

- (void)brandButtonClick:(UIButton *)button {
    [UIView animateWithDuration:0.5 animations:^{
        self.backScrollView.contentOffset = CGPointMake(0, 0);
        [self.topBrandButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.writerButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    }];
    
}

- (void)writerButtonClick:(UIButton *)button {
    [UIView animateWithDuration:1 animations:^{
        self.backScrollView.contentOffset = CGPointMake(WIDTH, 0);
        [self.topBrandButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.writerButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }];
}

- (void)createWriterData {
    self.writerArray = [NSMutableArray array];
    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    [ZWYNetTool GET:@"http://mobile.iliangcang.com/topic/magazineAuthorList/?&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981&user_token=03723b5fa4100c1079e788f94d65908d" andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSArray *data = result[@"data"][@"items"];
        for (NSDictionary *dic in data) {
            MagzineWriterModel *writer = [MagzineWriterModel modelWithDic:dic];
            [self.writerArray addObject:writer];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.writertableView reloadData];
            });
        }
    } andFailureBlock:^(NSError *error) {
    }];
}
// 作者的tableView
- (void)createWriterTableView {
    self.writertableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH, 64, WIDTH, HEIGHT - 108) style:UITableViewStylePlain];
    self.writertableView.delegate = self;
    self.writertableView.dataSource = self;
    self.writertableView.rowHeight = 80;
    [self.backScrollView addSubview:self.writertableView];
    
    [self.writertableView registerClass:[WriterTableViewCell class] forCellReuseIdentifier:@"writerReuse"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.collectArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MagzineCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectReuse" forIndexPath:indexPath];
    MagzineBrandCollectModel *magzine = [MagzineBrandCollectModel new];
    magzine = self.collectArray[indexPath.row];
    [cell.picImageView sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@",  magzine.thumb]]];
    cell.typeLabel.text = magzine.cat_name;
    return cell;
}

// 点击collectionVIew的cell
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.writerId = nil;
    self.idStr = [NSString string];
    self.aView.hidden = YES;
    self.magzineButton.hidden = YES;
    self.brandButton.hidden = NO;
    self.dataButton.hidden = NO;
    [UIView animateWithDuration:1 animations:^{
        self.topViewButton.frame = CGRectMake(0, 0, WIDTH, 64);
        [self.view addSubview:self.topViewButton];
        self.tableView.frame = CGRectMake(0, 64, WIDTH, HEIGHT - 64);
    }];
    self.titleLabel.frame = CGRectMake(self.topViewButton.bounds.size.width / 2 - 25, 25, 50, 30);
    // 点击的时候获取id
    self.idStr = [self.collectArray[indexPath.row] cat_id];
    [self createData];
}

// 只有刷新 没有加载
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (self.tableView.contentOffset.y < 0) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.label.text = NSLocalizedString(@"loading", @"HUD loading title");
        NSLog(@"下拉刷新");
        [self createData];
        //        [self.tableView reloadData];
        [hud hideAnimated:YES afterDelay:1];
        
    }
}

- (void)createData {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"loading", @"HUD loading title");

    self.str7 = [NSString string];
    
    NSDictionary *headDic = @{@"Host": @"mobile.iliangcang.com", @"Proxy-Connection": @"keep-alive", @"Accept": @"*/*", @"Accept-Language": @"zh-Hans-CN;q=1, en-CN;q=0.9", @"Connection": @"keep-alive", @"User-Agent": @"iLiangCang/3.0.0 (iPhone; iOS 9.2.1; Scale/2.00) Paros/3.2.13"};
    
    NSString *str1 = @"http://mobile.iliangcang.com/topic/magazineList/?";
    NSString *str2 = @"cat_id=";
    NSString *str3 = self.idStr;
    NSString *str4 = @"&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981&user_token=03723b5fa4100c1079e788f94d65908d";
    NSString *str6 = @"author_id=";
    NSString *str8 = self.writerId;
    if ((self.idStr.length == 0) && (self.writerId.length == 0)) {
        self.str7 = @"http://mobile.iliangcang.com/topic/magazineList/?&app_key=iPhone&v=3.0.0&sig=254F2CCC-7E43-4833-A27D-7D12702F5981&user_token=03723b5fa4100c1079e788f94d65908d";
    } else if ((self.writerId.length != 0) && (self.idStr.length == 0)) {
        self.str7 = [[[str1 stringByAppendingString:str6] stringByAppendingString:str8] stringByAppendingString:str4];
        
    } else if((self.idStr.length != 0) && (self.writerId.length ==0)){
        self.str7 = [[[str1 stringByAppendingString:str2] stringByAppendingString:str3] stringByAppendingString:str4];
    }
    // 点击collectionVIew的cell的网址
    // 全部杂志的网址
    [ZWYNetTool GET:self.str7  andBody:nil andHeader:headDic andResponse:ZWYJSON andSuccessBlock:^(id result) {
        self.magzineArray = [NSMutableArray array];
        self.dataArray = [NSMutableArray array];
        self.dataArray = result[@"data"][@"items"][@"keys"];
        for (NSInteger i = 0; i < self.dataArray.count; i++) {
            [self.magzineArray addObject:result[@"data"][@"items"][@"infos"][self.dataArray[i]]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView reloadData];
            });
        }
        if (self.magzineArray.count != 0) {
            [hud hideAnimated:YES afterDelay:0.5];
        }
    } andFailureBlock:^(NSError *error) {
    }];
}

- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 110) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = [UIColor colorWithWhite:0.094 alpha:1.000];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 170;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[MagzineTableViewCell class] forCellReuseIdentifier:@"reuse"];
    // tableView头视图的注册 这时包含了头尾视图 这里 我们不需要头视图 所以在设置头视图高度的协议方法中 设置头视图高度 但不能为0 给一个很小的值
    [self.tableView registerClass:[MagzineFootView class] forHeaderFooterViewReuseIdentifier:@"footReuse"];
}

// 设置分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if ([tableView isEqual:self.writertableView]) {
        return 1;
    } else {
        return self.dataArray.count;
    }
}

// 设置头视图的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.0001;
}

// 设置尾视图的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if ([tableView isEqual:self.writertableView]) {
        return 0.00001;
    } else {
        return 30;
    }
}

// 自定义尾视图
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if ([tableView isEqual:self.writertableView]) {
        return nil;
    } else {
        MagzineFootView *footView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"footReuse"];
        footView.dataLabel.text = [NSString stringWithFormat:@"一 %@ 一", self.dataArray[section]];
        return footView.dataLabel;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([tableView isEqual:self.writertableView]) {
        return self.writerArray.count;
    } else {
        return [self.magzineArray[section] count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([tableView isEqual:self.writertableView]) {
        WriterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"writerReuse" forIndexPath:indexPath];
        cell.nameLabel.text = [self.writerArray[indexPath.row] author_name];
        cell.titleLabel.text = [self.writerArray[indexPath.row] note];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [self.writerArray[indexPath.row] thumb]]]];
        return cell;
    } else {
        MagzineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
        cell.titleLabel.text = self.magzineArray[indexPath.section][indexPath.row][@"topic_name"];
        cell.typeLabel.text = self.magzineArray[indexPath.section][indexPath.row][@"cat_name"];
        [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:self.magzineArray[indexPath.section][indexPath.row][@"cover_img"]]];
        
        self.dataStr = self.dataArray[indexPath.section];
        
        self.dataButton.titleLabel.font = [UIFont systemFontOfSize:12];
        self.dataButton.frame = CGRectMake(0, 27, 110, 20);
        self.dataButton.titleLabel.textAlignment = 0;
        [self.dataButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.dataButton setTitle:self.dataStr forState:UIControlStateNormal];
        [self.topViewButton addSubview:self.dataButton];
        
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([tableView isEqual:self.tableView]) {
        MagzineDetailViewController *detailVC = [[MagzineDetailViewController alloc] init];
        detailVC.dataArray = self.magzineArray;
        detailVC.sectionSuffix = indexPath.section;
        detailVC.rowSuffix = indexPath.row;
        [self.navigationController pushViewController:detailVC animated:NO];
    } else if ([tableView isEqual:self.writertableView]) {
        // 获取writerid拼接网址
        self.idStr = nil;
        self.dataButton.hidden = NO;
        self.aView.hidden = YES;
        self.magzineButton.hidden = YES;
        self.brandButton.hidden = NO;
        [UIView animateWithDuration:1 animations:^{
            self.topViewButton.frame = CGRectMake(0, 0, WIDTH, 64);
            [self.view addSubview:self.topViewButton];
            self.tableView.frame = CGRectMake(0, 64, WIDTH, HEIGHT - 64);
        }];
        self.titleLabel.frame = CGRectMake(self.topViewButton.bounds.size.width / 2 - 25, 25, 50, 30);
        self.writerId = [NSString string];
        self.writerId = [self.writerArray[indexPath.row] author_id];
        [self createData];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
